package com.onlyphoto.onlymall.mvp.view.activity

import android.view.View
import com.onlyphoto.onlymall.MyApplication
import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.base.BaseActivity
import com.onlyphoto.onlymall.bean.request.PwdBean
import com.onlyphoto.onlymall.listeners.NoDoubleClickListener
import com.onlyphoto.onlymall.mvp.contract.CSetPwd
import com.onlyphoto.onlymall.mvp.presenter.PSetPwdImpl
import com.onlyphoto.onlymall.utils.AndroidUtils
import com.onlyphoto.onlymall.utils.Constants
import com.onlyphoto.onlymall.utils.SharePreferenceUtil
import com.onlyphoto.onlymall.utils.ToastUtil
import kotlinx.android.synthetic.main.activity_setpwd.*


class SetPwdActivity : BaseActivity<PSetPwdImpl>(), CSetPwd.IVSetPwd {

    override fun retry() {}

    override fun init() {

    }

    override fun initListener() {
        AndroidUtils.isButtonEnable(intArrayOf(6, 6), commit, et_pwd, pwd_confirm)
        back.setOnClickListener{
            finish()
        }

        commit.setOnClickListener(object : NoDoubleClickListener(){
            override fun onNoDoubleClick(view: View?) {
                if (et_pwd.text.toString() != pwd_confirm.text.toString()) {
                    showToast("两次密码输入不一致")
                } else {
                    mPresenter?.setPwd()
                }
            }

        })
    }

    override fun loadData() {
    }

    override fun getPwdBean(): PwdBean {
        val bean = PwdBean()
        bean.post_type = 1
        bean.new_password = et_pwd.text.toString()
        bean.user_token = SharePreferenceUtil.getInstance(MyApplication.app).token
        return bean
    }

    override fun setPwdSuccess() {
        ToastUtil.showToastInCenter(this, "密码设置成功")
        SharePreferenceUtil.getInstance(this).setIntData(Constants.IS_SET_PWD, 1)
        finish()
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun isFullScreen(): Boolean {
        //是否沉浸式， 默认非沉浸式
        return false
    }

    public override fun initCustomerStatusManager() {}

    override fun setContentViewId(): Int {
        return R.layout.activity_setpwd
    }

    override fun createPresenter() {
        mPresenter = PSetPwdImpl(mContext, this)
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

}
